/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package racesuitefx.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Wolfgang
 */
@Entity
@Table(name = "starter")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Starter.findAll", query = "SELECT s FROM Starter s"),
    @NamedQuery(name = "Starter.findByBirthDate", query = "SELECT s FROM Starter s WHERE s.birthDate = :birthDate"),
    @NamedQuery(name = "Starter.findByFirstName", query = "SELECT s FROM Starter s WHERE s.firstName = :firstName"),
    @NamedQuery(name = "Starter.findByLastName", query = "SELECT s FROM Starter s WHERE s.lastName = :lastName"),
    @NamedQuery(name = "Starter.findByStartNumber", query = "SELECT s FROM Starter s WHERE s.startNumber = :startNumber"),
    @NamedQuery(name = "Starter.findByRaceId", query = "SELECT s FROM Starter s WHERE s.starterPK.raceId = :raceId"),
    @NamedQuery(name = "Starter.findByTagId", query = "SELECT s FROM Starter s WHERE s.starterPK.tagId = :tagId")})
public class Starter implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected StarterPK starterPK;
    @Column(name = "birthDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date birthDate;
    @Column(name = "firstName")
    private String firstName;
    @Column(name = "lastName")
    private String lastName;
    @Column(name = "startNumber")
    private Integer startNumber;
    @JoinColumn(name = "raceId", referencedColumnName = "raceId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Race race;
    @JoinColumn(name = "tagId", referencedColumnName = "tagId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Tag tag;

    public Starter() {
    }

    public Starter(StarterPK starterPK) {
        this.starterPK = starterPK;
    }

    public Starter(int raceId, String tagId) {
        this.starterPK = new StarterPK(raceId, tagId);
    }

    public StarterPK getStarterPK() {
        return starterPK;
    }

    public void setStarterPK(StarterPK starterPK) {
        this.starterPK = starterPK;
    }

    public Date getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(Date birthDate) {
        this.birthDate = birthDate;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Integer getStartNumber() {
        return startNumber;
    }

    public void setStartNumber(Integer startNumber) {
        this.startNumber = startNumber;
    }

    public Race getRace() {
        return race;
    }

    public void setRace(Race race) {
        this.race = race;
    }

    public Tag getTag() {
        return tag;
    }

    public void setTag(Tag tag) {
        this.tag = tag;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (starterPK != null ? starterPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Starter)) {
            return false;
        }
        Starter other = (Starter) object;
        if ((this.starterPK == null && other.starterPK != null) || (this.starterPK != null && !this.starterPK.equals(other.starterPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "racesuitefx.entities.Starter[ starterPK=" + starterPK + " ]";
    }
    
}
